package com.ruoyi.shenhe.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shenhe.domain.Approved;
import com.ruoyi.shenhe.service.IApprovedService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 申请审核Controller
 * 
 * @author ruoyi
 * @date 2023-04-05
 */
@Controller
@RequestMapping("/shenhe/approved")
public class ApprovedController extends BaseController
{
    private String prefix = "shenhe/approved";

    @Autowired
    private IApprovedService approvedService;

    @RequiresPermissions("shenhe:approved:view")
    @GetMapping()
    public String approved()
    {
        return prefix + "/approved";
    }

    /**
     * 查询申请审核列表
     */
    @RequiresPermissions("shenhe:approved:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Approved approved)
    {
        startPage();
        List<Approved> list = approvedService.selectApprovedList(approved);
        return getDataTable(list);
    }

    /**
     * 导出申请审核列表
     */
    @RequiresPermissions("shenhe:approved:export")
    @Log(title = "申请审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Approved approved)
    {
        List<Approved> list = approvedService.selectApprovedList(approved);
        ExcelUtil<Approved> util = new ExcelUtil<Approved>(Approved.class);
        return util.exportExcel(list, "申请审核数据");
    }

    /**
     * 新增申请审核
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存申请审核
     */
    @RequiresPermissions("shenhe:approved:add")
    @Log(title = "申请审核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Approved approved)
    {
        return toAjax(approvedService.insertApproved(approved));
    }

    /**
     * 修改申请审核
     */
    @RequiresPermissions("shenhe:approved:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Approved approved = approvedService.selectApprovedById(id);
        mmap.put("approved", approved);
        return prefix + "/edit";
    }

    /**
     * 修改保存申请审核
     */
    @RequiresPermissions("shenhe:approved:edit")
    @Log(title = "申请审核", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Approved approved)
    {
        return toAjax(approvedService.updateApproved(approved));
    }

    /**
     * 删除申请审核
     */
    @RequiresPermissions("shenhe:approved:remove")
    @Log(title = "申请审核", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(approvedService.deleteApprovedByIds(ids));
    }
}
